package com.viboo.concern.service.impl;

import com.viboo.concern.dao.UserMapper;
import com.viboo.concern.entity.User;
import com.viboo.concern.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author avanline
 * @descriotion
 * @date 2018-02-28 18:18
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public boolean addUser(User user) throws Exception {
        try {
            if (userMapper.selectByOpenId(user.getOpenId()) != null)
                return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return userMapper.insert(user) == 1;
    }

    @Override
    public boolean updateShareTime(User user) throws Exception {
        user.setShareTime(System.currentTimeMillis());
        return userMapper.updateShareTime(user) == 1;
    }

    @Override
    public User selectUser(String openId) throws Exception {
        return userMapper.selectByOpenId(openId);
    }
}
